# 从mypakge中导入导包路径
from goods.models import SPU
from meiduo_admin.mypakge import *
from goods.models import Brand,GoodsCategory
from rest_framework.serializers import *

class SPUSerializer(serializers.ModelSerializer):
    """
    spu表序列化器
    """
    brand = serializers.StringRelatedField(read_only=True)
    brand_id = serializers.IntegerField()
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()

    class Meta:
        model = SPU
        exclude = [
                    'category1',
                    'category2',
                    'category3'
                   ]


class SPUBrandSerializer(serializers.ModelSerializer):
    """品牌序列化器"""
    class Meta:
        model = Brand
        fields = "__all__"


class SPUCategorySerializer(serializers.ModelSerializer):
    """获取一级分类信息"""
    class Meta:
        model = GoodsCategory
        fields = [
            'id',
            'name'
        ]


class SPUCategory_2_3_Serializer(serializers.ModelSerializer):
    """获取2，3，级分类信息"""
    class Meta:
        model = GoodsCategory
        fields = '__all__'